<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"  %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<HEAD>
<style type="text/css">
body, a, table, div, span, td, th, input, select{font:9pt;font-family:  Verdana, Arial, Helvetica, sans-serif;}
body {padding:5px}
</style>

<script language="JavaScript" src="dialog.js"></script>

<script language="JavaScript">
var sAction = "";
var sTitle = "";

var oControl;
var oSeletion;
var sRangeType;

var sImage = "";
var sRepeat = "";
var sAttachment = "";

var sCheckFlag = "sys";

if (URLParams['action'] == "other"){
	sAction = "OTHER"
	sTitle = "<bean:message bundle='webEditor'   key='webEditor.Set' />"
	sImage = dialogArguments.d_image.value;
	sRepeat = dialogArguments.d_repeat.value;
	sAttachment = dialogArguments.d_attachment.value;
	sCheckFlag = "url";
}else{

	sAction = "INSERT";
	sTitle = "<bean:message bundle='webEditor'   key='webEditor.Page' />";

	oSelection = dialogArguments.eWebEditor.document.selection.createRange();
	sRangeType = dialogArguments.eWebEditor.document.selection.type;

	if (sRangeType == "Control") {
		oControl = GetControl(oSelection, "TABLE");
	}else{
		oControl = GetImageParent(oSelection.parentElement());
	}
	if (oControl) {
		switch(oControl.tagName){
		case "TD":
			sTitle = "<bean:message bundle='webEditor'   key='webEditor.Cell' />";
			break;
		case "TR":
		case "TH":
			sTitle = "<bean:message bundle='webEditor'   key='webEditor.TableRow' />";
			break;
		default:
			sTitle = "<bean:message bundle='webEditor'   key='webEditor.Table' />";
			break;
		}
		sAction = "MODI";
		sImage = oControl.style.backgroundImage;
		sRepeat = oControl.style.backgroundRepeat;
		sAttachment = oControl.style.backgroundAttachment;
		sCheckFlag = "url";
		sImage = sImage.substr(4, sImage.length-5)
	}

}
document.write("<title><bean:message bundle='webEditor'   key='webEditor.BackImage.Title' />(" + sTitle + ")</title>");

function InitDocument(){
	SearchSelectValue(d_repeat, sRepeat.toLowerCase());
	SearchSelectValue(d_attachment, sAttachment.toLowerCase());
	d_fromurl.value = sImage;
}

function GetImageParent(obj){
	while(obj!=null && obj.tagName!="TD" && obj.tagName!="TR" && obj.tagName!="TH" && obj.tagName!="TABLE")
		obj=obj.parentElement;
	return obj;
}

function GetControl(obj, sTag){
	obj=obj.item(0);
	if (obj.tagName==sTag){
		return obj;
	}
	return null;
}

function RadioClick(what){
	switch(what){
	case "url":
		d_checkfromsys.checked=false;
		d_checkcancel.checked=false;
		d_fromurl.disabled=false;
		d_fromsys.disabled=true;
		break;
	case "file":
		d_checkfromsys.checked=false;
		d_checkcancel.checked=false;
		d_fromurl.disabled=true;
		d_fromsys.disabled=true;
		break;
	case "sys":
		d_checkfromsys.checked=true;
		d_checkcancel.checked=false;
		d_fromurl.disabled=true;
		d_fromsys.disabled=false;
		break;
	case "cancel":
		d_checkfromsys.checked=false;
		d_checkcancel.checked=true;
		d_fromurl.disabled=true;
		d_fromsys.disabled=true;
		break;
	}
}

function UploadLoaded(){

	RadioClick(sCheckFlag);
}



function UploadSaved(sFileName){
	d_fromurl.value=GetHttpUrl(config.StyleUploadDir+"/"+sFileName);
	ReturnValue();
}

function ReturnValue(){
	if (d_fromurl.value==""){
		sImage = "";
		sRepeat = "";
		sAttachment = "";
	}else{
		if (sAction == "OTHER"){
			sImage = d_fromurl.value;
		}else{
			sImage = "url(" + d_fromurl.value + ")";
		}
		sRepeat = d_repeat.options[d_repeat.selectedIndex].value;
		sAttachment = d_attachment.options[d_attachment.selectedIndex].value;
	}

	switch(sAction){
	case "MODI":
		oControl.style.backgroundImage = sImage;
		oControl.style.backgroundRepeat = sRepeat;
		oControl.style.backgroundAttachment = sAttachment;
		break;
	case "OTHER":
		dialogArguments.d_image.value = sImage;
		dialogArguments.d_repeat.value = sRepeat;
		dialogArguments.d_attachment.value = sAttachment;
		break;
	default:
		dialogArguments.setHTML("<table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%'><tr><td valign=top style='background-image:"+sImage+";background-repeat:"+sRepeat+";background-attachment:"+sAttachment+";'>"+dialogArguments.getHTML()+"</td></tr></table>");
		break;
	}

	window.returnValue = null;
	window.close();
}


function ok(){

	if (d_checkfromsys.checked){
		d_fromurl.value=GetHttpUrl("sysimage/bg/"+d_fromsys.options[d_fromsys.selectedIndex].value);
		ReturnValue();
	}
	if (d_checkcancel.checked){
		d_fromurl.value="";
		ReturnValue();
	}
}


function DisableItems(){
	d_checkfromsys.disabled=true;
	d_checkcancel.disabled=true;
	d_fromurl.disabled=true;
	d_fromsys.disabled=true;
	d_repeat.disabled=true;
	d_attachment.disabled=true;
	Ok.disabled=true;
}


function AbleItems(){
	d_checkfromsys.disabled=false;
	d_checkcancel.disabled=false;
	d_fromurl.disabled=false;
	d_fromsys.disabled=false;
	d_repeat.disabled=false;
	d_attachment.disabled=false;
	Ok.disabled=false;
}
function UploadImport(){
   var dEL = document.all("d_fromurl");
    var url = "<html:rewrite page='/protected/resmgr/initDirectory.do' />?CallFromTemplateDesign=true";
	var arr = showModalDialog(url,window,"dialogWidth:750px;dialogHeight:600px;help:no;scroll:yes;status:no");
	if (arr) {
		dEL.value=arr;
	}
}

</script>
</HEAD>

<BODY bgColor=menu onload="InitDocument()">

<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
	<td>
	<fieldset>
	<legend><bean:message bundle='webEditor'   key="webEditor.Image.Source" /></legend>
	<table border=0 cellpadding=0 cellspacing=0>
	<tr><td colspan=9 height=5></td></tr>
    <tr>
		<td width=7></td>
 		<td colspan=5><input type=text id="d_fromurl" style="width:220px" size=25 value="" ></td>
		<td width=5></td>
		<td width=7><input type=button value="<bean:message bundle='webEditor'  key='webEditor.InsertImage.Upload' />" onclick="UploadImport()"></td>
		<td width=5></td>
		<td width=5><input type=submit value="<bean:message bundle='webEditor'  key='webEditor.InsertImage.Import' />" onclick="UploadImport()"></td>
	</tr>
	<tr><td colspan=9 height=5></td></tr>
	<tr>
		<td width=7></td>
		<td width=54 align=right onclick="RadioClick('sys')"><input type=radio id="d_checkfromsys" onclick="RadioClick('sys')"><bean:message bundle='webEditor'   key="webEditor.BackImage.System" /></td>
		<td width=5></td>
		<td>
			<select id="d_fromsys" size=1>
			<option value="snow.gif" selected>Snow</option>
			<option value="Nature.jpg">Nature</option>
			<option value="Clear.jpg">Fairness </option>
 			</select>
		</td>
		<td nowrap="nowrap" onclick="RadioClick('cancel')"><input type=radio id="d_checkcancel" onclick="RadioClick('cancel')"><bean:message bundle='webEditor'  key="webEditor.BackImage.Cancel.BackImage" /></td>
		<td width=7></td>
	</tr>
	<tr><td colspan=9 height=5></td></tr>
	</table>
	</fieldset>
	</td>
</tr>
<tr><td height=5></td></tr>
<tr>
	<td>
	<fieldset>
	<legend><bean:message bundle='webEditor'   key="webEditor.Image.Effect" /></legend>
	<table border=0 cellpadding=0 cellspacing=0>
	<tr><td colspan=9 height=5></td></tr>
	<tr>
		<td width=7></td>
		<td><bean:message bundle='webEditor'   key="webEditor.BackImage.TileStyle" /></td>
		<td width=5></td>
		<td>
			<select id=d_repeat size=1 style="width:72px">
			<option value='' selected><bean:message bundle='webEditor'   key="webEditor.HorAlign.option.1" /></option>
			<option value='repeat'><bean:message bundle='webEditor'   key="webEditor.BackImage.TileStyle.option.1" /></option>
			<option value='no-repeat'><bean:message bundle='webEditor'   key="webEditor.BackImage.TileStyle.option.2" /></option>
			<option value='repeat-x'><bean:message bundle='webEditor'   key="webEditor.BackImage.TileStyle.option.3" /></option>
			<option value='repeat-y'><bean:message bundle='webEditor'   key="webEditor.BackImage.TileStyle.option.4" /></option>
			</select>
		</td>
		<td width=40></td>
		<td><bean:message bundle='webEditor'   key="webEditor.BackImage.Marquee" /></td>
		<td width=5></td>
		<td>
			<select id=d_attachment style="width:72px" size=1>
			<option value='' selected><bean:message bundle='webEditor'   key="webEditor.HorAlign.option.1" /></option>
			<option value='scroll'><bean:message bundle='webEditor'   key="webEditor.BackImage.Marquee.option.1" /></option>
			<option value='fixed'><bean:message bundle='webEditor'   key="webEditor.BackImage.Marquee.option.2" /></option>
            </select>
		</td>
		<td width=7></td>
	</tr>
	<tr><td colspan=9 height=5></td></tr>
	</table>
	</fieldset>
	</td>
</tr>
<tr><td height=5></td></tr>
<tr><td align=right><input type=submit value='<bean:message bundle='webEditor'   key="webEditor.Confirm" />' id=Ok onclick="ok()">&nbsp;&nbsp;<input type=button value='<bean:message bundle='webEditor'   key="webEditor.Cancel" />' onclick="window.close();"></td></tr>
</table>
